package core.network.client2game.handler.union;

import business.global.club.ClubMember;
import business.global.club.ClubMgr;
import business.global.union.UnionMgr;
import business.player.Player;
import com.ddm.server.common.utils.CommTime;
import com.ddm.server.websocket.def.ErrorCode;
import com.ddm.server.websocket.exception.WSException;
import com.ddm.server.websocket.handler.requset.WebSocketRequest;
import com.google.gson.Gson;
import core.network.client2game.handler.PlayerHandler;
import core.network.http.proto.SData_Result;
import jsproto.c2s.cclass.union.UnionDefine;
import jsproto.c2s.iclass.union.CUnion_MemberExamineList;
import jsproto.c2s.iclass.union.CUnion_MemberExamineOperate;

import java.io.IOException;
import java.util.Objects;

/**
 * 赛事成员审核操作
 * @author zaf
 *
 */
public class CUnionMemberExamineOperate extends PlayerHandler {

	@SuppressWarnings("rawtypes")
	@Override
	public void handle(Player player, WebSocketRequest request, String message)
			throws WSException, IOException {
    	final CUnion_MemberExamineOperate req = new Gson().fromJson(message, CUnion_MemberExamineOperate.class);
    	SData_Result result = UnionMgr.getInstance().getUnionMemberMgr().getUnionMemberExamineOperate(req.getUnionId(),req.getClubId(),req.getOpPid(),req.getOpClubId(),player.getPid(),req.getType(),req.getOperate());
    	if(ErrorCode.Success.equals(result.getCode())) {
    		if(UnionDefine.UNION_EXAMINE_TYPE.checkMatch(req.getType())){
				//中至重赛 另外执行一次裁定作弊
				ClubMember doClubMember = ClubMgr.getInstance().getClubMemberMgr().getClubMember(req.getClubId(), req.getOpPid());
				if(Objects.nonNull(doClubMember)&&doClubMember.getClubMemberBO().isZhongZhiClub()){
					doClubMember.getClubMemberBO().saveLastRuleTime(CommTime.nowSecond());
				}
			}
    		request.response(result.getData());
    	} else {
    		request.error(result.getCode(), result.getMsg());
    	}
	}

}
